package com.hatricks.is.base.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.StringJoiner;

@Data
public class Test {

    public static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }

        @Override
        public String toString() {
            return new StringJoiner(", ", ListNode.class.getSimpleName() + "[", "]")
                    .add("val=" + val)
                    .add("next=" + next)
                    .toString();
        }
    }

    public static ListNode reverseList(ListNode head) {
        ListNode pre = null;
        // 将头节点赋值给当前节点
        ListNode current = head;
        ListNode next;

        while (current != null) {
            next = current.next; // 讲下一个节点提前保存起来
            current.next = pre;
            pre = current;
            current = next;
        }
        return pre;
    }

    public static void main(String[] args) {
        // 1. 反转链表
        //ListNode head = new ListNode(1, new ListNode(2, new ListNode(3, new ListNode(4, new ListNode(5)))));
        //ListNode reverseNode = reverseList(head);
        //System.out.println(reverseNode);
    }


    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Student {
        public String name;
        public String age;
    }
}
